package com.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.entity.Person;

public class ObjSeria {
	public static void main(String[] args) throws IOException,
			ClassNotFoundException {
//		String pathname = "C:" + File.separator + "zz";
//		File dir = new File(pathname);
//		if (!dir.exists()) {
//			dir.mkdirs();
//		}
//
//		for (int i = 0; i < 100; i++) {
//			File file = new File(dir, "person" + i + ".txt");
//			if (!file.exists()) {
//				file.createNewFile();
//			}
//			Person p = new Person("tom" + i, 18 + i, "男");
//			save(file, p);
//			Person p2 = (Person) read(file);
//			System.out.println("name=" + p2.getName());
//			System.out.println("age=" + p2.getAge());
//
//		}
		
		aaa();

	}
	
	static int aaa(){
		int a;
		try {
			a=10;
			return a;
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		finally{
			System.out.println("finally");
		}
		return 0;
	}

	static void save(File file, Object obj) throws IOException {
		// Student对象序列化过程
		FileOutputStream fos = new FileOutputStream(file, true);
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(obj);
		oos.flush();
		oos.close();
		fos.close();
	}

	static Object read(File file) throws IOException, ClassNotFoundException {
		// Student对象反序列化过程
		FileInputStream fis = new FileInputStream(file);
		ObjectInputStream ois = new ObjectInputStream(fis);
		return ois.readObject();

	}

}
